<%@include file="connection.jsp"%>
<%
		String fname = request.getParameter("fname");
		String lname = request.getParameter("lname");
		String address= request.getParameter("address");
		String ssn = request.getParameter("ssn");    
        String patientId = request.getParameter("patient_id");
        
        StringBuffer query = new StringBuffer("select * from tblpatientinformation");
        if(fname!=null){
        

        	if(fname.length() > 0)        	
        	{
        		query.append(" where FirstName like '%"+fname+"%'");
        	}
        	if(lname.length() > 0)
        	{	
	        	if(fname.length() > 0){
        			query.append(" and LastName like '%"+lname+"%'");
        		}else{
        			query.append(" where LastName like '%"+lname+"%'");
        		}
        	}
        	
        }else if(address!=null){
        	if(address.length() > 0)
        	{
        		query.append(" where address like '%"+address+"%'");
        	}
        }else if(ssn!=null){
        	if(ssn.length() > 0)
        	{
        		query.append(" where SSN like '%"+ssn+"%'");
        	}
        }else if(patientId !=null){
        	if(patientId .length() > 0)
        	{
        		query.append(" where patientID like '%"+patientId +"%'");
        	}
        }
        query.append(" order by patientID");
        Connection c = getConnection(session);
        Statement s = c.createStatement();
        %>
        <table cellpadding="0" cellspacing="0" width="800">
        <tr>
        	<th></th>
        	<th>Patient ID</th>
        	<th>First Name</th>
        	<th>Last Name</th>
			<th>DOB</th>
			<th>SSN</th>
			<th>Home Phone</th>
        </tr>        
        <%
        //System.out.println(query);
        ResultSet rs = s.executeQuery(query.toString());
        while(rs.next())
        {
	   %>
 <tr>
	<td><input type=radio name="pid" value="<%=rs.getString("patientID")%>"/></td>
	<td><%=rs.getString("patientID")%></td>
	<td><%=rs.getString("FirstName")%></td>
	<td><%=rs.getString("LastName")%></td>
	<td><%=rs.getString("DOB")%></td>
	<td><%=rs.getString("SSN")%></td>
	<td><%=rs.getString("HomePhone")%></td>
</tr>

<%
}	
rs.close();
s.close();
c.close();
%>
</table>